package com.cxt.controller;

import com.cxt.entity.MessageNotification;
import com.cxt.result.Result;
import com.cxt.service.IMessageNotificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 消息通知表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2025-02-27
 */
@RestController
@RequestMapping("/messageNotification")
@Slf4j
public class MessageNotificationController {
    @Autowired
    private IMessageNotificationService messageNotificationService;
    /**
     * 获取该用户的消息
     */
    @GetMapping("/get")
    public Result getMessageNotification() {
        log.info("获取该用户的消息");
        List<MessageNotification> messageNotification = messageNotificationService.getMyMsg();
        return Result.success(messageNotification);
    }
    /**
     * 获取紧急求助消息
     */
    @GetMapping("/getHelp")
    public Result getHelpMessageNotification() {
        log.info("获取紧急求助消息");
        List<MessageNotification> messageNotification = messageNotificationService.getHelpMsg();
        return Result.success(messageNotification);
    }
    /**
     * 已读消息
     */
    @GetMapping("/read")
    public Result readMessageNotification(Long id) {
        log.info("已读消息");
        MessageNotification byId = messageNotificationService.getById(id);
        byId.setIsRead(true);
        boolean b = messageNotificationService.updateById(byId);
        if (b) {
            return Result.success("已读成功");
        }
        return Result.error("已读失败");
    }
}
